package com.alibaba.moco.springboot;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.alibaba.moco.monitor.ScriptClassLoader;
import com.alibaba.moco.monitor.UpdateRunnable;
/**
 * 
 * 类InitScriptRunner.java的实现描述：TODO groovy脚本初始化 脚本更新线程启动
 * @author wb-lj240895 2016年12月8日 下午1:54:30
 */
@Component
@Order(Integer.MAX_VALUE) //优先级最高
public class InitScriptRunner implements CommandLineRunner {

    private static final Logger logger = LoggerFactory.getLogger(InitScriptRunner.class);
    
    @Override
    public void run(String... arg0) throws Exception {
        logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>Groovy脚本初始化<<<<<<<<<<<<<<<<<<<<<");
        ScriptClassLoader.init();
        ScheduledThreadPoolExecutor scheduled = new ScheduledThreadPoolExecutor(5);
        scheduled.scheduleWithFixedDelay(new UpdateRunnable(), 5, 20, TimeUnit.SECONDS);
    }

}
